#include "YBskn.h"
#include "iRegstryAssist.h"

iRegstryAssist::iRegstryAssist(void)
{
}

iRegstryAssist::~iRegstryAssist(void)
{
}

bool iRegstryAssist::SetSkinRegistry( char* pRegName, int nType, LPBYTE datas, size_t size )
{
	HKEY KeyData; 
	LONG lResult  = RegConnectRegistry( NULL, HKEY_LOCAL_MACHINE, &KeyData );
	if ( lResult != ERROR_SUCCESS )
		return false;

	DWORD nDisp = KEY_ALL_ACCESS;
	lResult  = RegOpenKeyEx( HKEY_LOCAL_MACHINE, MAX_GAMESKIN_REGPATH, 0, KEY_ALL_ACCESS, &KeyData );	
	if( lResult != ERROR_SUCCESS )
	{
		RegCreateKeyEx(HKEY_LOCAL_MACHINE, MAX_GAMESKIN_REGPATH, 0, NULL, REG_OPTION_NON_VOLATILE
		, KEY_ALL_ACCESS, NULL, &KeyData, &nDisp );
	}

	// Setting Type
	RegSetValueEx( KeyData, pRegName, 0, nType, datas, size );
	return true;
}


void iRegstryAssist::SaveSkinOptionRegistry( iDumpMaxData* pData )
{
	if ( !pData )
		return;

	char regname[iDumpMaxData::eOPTION_MAX][128] 
	= { "CHARACTER_TYPE", "CHARACTER_CLASS", "FACE_CHECK", "HAIR_CHECK", "BODY_CHECK", "HAND_CHECK"
		, "FOOT_CHECK",	"SET_CHECK", "CLOCK_CHECK", "WEPON_CHECK", "BIPED_CHECK", "TEXTURE_CHECK"
		, "ITEM_CHECK", "NPC_CHCEK", "NPCWEAPON_CHCEK","NPCTEXTURE_CHECK", "FACEBIPED_CHECK"
		, "ARMBIPED_CHECK", "TURNNORMAL_CHECK" };
	for ( int i = 0 ; i < iDumpMaxData::eOPTION_MAX ; i++ )
	{
		SetSkinRegistry( regname[i], REG_DWORD, (LPBYTE)&pData->m_ExportOption[i].m_bFlag, sizeof(DWORD) );
	}

	char regIndexname[iDumpMaxData::eOPTION_MAX][256]
	= { "INDEX_CHARACTER_TYPE", "INDEX_CHARACTER_CLASS", "INDEX_FACE", "INDEX_HAIR"
		, "INDEX_BODY", "INDEX_HAND", "INDEX_FOOT","INDEX_SET", "INDEX_CLOCK"
		, "INDEX_WEAPON", "INDEX_BIPED", "INDEX_TEXTURE", "INDEX_ITEM", "INDEX_NPC", "INDEX_NPCWEAPON"
		, "INDEX_NPCTEXTUREINDEX", "INDEX_FACEBIPED", "INDEX_ARMBIPED", "INDEX_TURNNORMAL" };
	for ( int i = 0 ; i < iDumpMaxData::eOPTION_MAX ; i++ )
	{
		SetSkinRegistry( regIndexname[i], REG_DWORD, (LPBYTE)&pData->m_ExportOption[i].m_Index, sizeof(DWORD) );
	}
	char regCombo[4][256] = {"COMBO_CHARACTERTPYE", "COMBO_CHARACTER_CLASS", "COMBO_NPCTYPE"
		, "COMBO_ITEMTYPE"};
	SetSkinRegistry( regCombo[0], REG_DWORD
		, (LPBYTE)&pData->m_ExportOption[iDumpMaxData::eOPTION_CHARACTERTYPE].m_SelectNum, sizeof(DWORD) );
	SetSkinRegistry( regCombo[1], REG_DWORD
		, (LPBYTE)&pData->m_ExportOption[iDumpMaxData::eOPTION_CHARACTERCLASS].m_SelectNum, sizeof(DWORD) );
	SetSkinRegistry( regCombo[2], REG_DWORD
		, (LPBYTE)&pData->m_ExportOption[iDumpMaxData::eOPTION_NPC].m_SelectNum, sizeof(DWORD) );
	SetSkinRegistry( regCombo[3], REG_DWORD
		, (LPBYTE)&pData->m_ExportOption[iDumpMaxData::eOPTION_ITEM].m_SelectNum, sizeof(DWORD) );
}
void iRegstryAssist::LoadSkinOptionRegistry( iDumpMaxData* pData )
{
	if ( !pData )
		return;

	char regname[iDumpMaxData::eOPTION_MAX][256] 
	= { "CHARACTER_TYPE", "CHARACTER_CLASS", "FACE_CHECK", "HAIR_CHECK", "BODY_CHECK", "HAND_CHECK"
		, "FOOT_CHECK","SET_CHECK", "CLOCK_CHECK", "WEPON_CHECK", "BIPED_CHECK", "TEXTURE_CHECK"
		, "ITEM_CHECK", "NPC_CHCEK", "NPCWEAPON_CHCEK","NPCTEXTURE_CHECK", "FACEBIPED_CHECK"
		, "ARMBIPED_CHECK", "TURNNORMAL_CHECK" };
	for ( int i = 0 ; i < iDumpMaxData::eOPTION_MAX ; i++ )
	{
		GetSkinRegistry( pData->m_ExportOption[i].m_bFlag, regname[i], sizeof(DWORD) );
	}
	char regIndexname[iDumpMaxData::eOPTION_MAX][256]
	= { "INDEX_CHARACTER_TYPE", "INDEX_CHARACTER_CLASS", "INDEX_FACE", "INDEX_HAIR"
		, "INDEX_BODY", "INDEX_HAND", "INDEX_FOOT","INDEX_SET", "INDEX_CLOCK"
		, "INDEX_WEAPON", "INDEX_BIPED", "INDEX_TEXTURE", "INDEX_ITEM", "INDEX_NPC", "INDEX_NPCWEAPON"
		, "INDEX_NPCTEXTUREINDEX", "INDEX_FACEBIPED", "INDEX_ARMBIPED", "INDEX_TURNNORMAL" };
	for ( int i = 0 ; i < iDumpMaxData::eOPTION_MAX ; i++ )
	{
		GetSkinRegistry( pData->m_ExportOption[i].m_Index, regIndexname[i], sizeof(DWORD) );
	}
	char regCombo[4][256] = {"COMBO_CHARACTERTPYE", "COMBO_CHARACTER_CLASS", "COMBO_NPCTYPE"
		, "COMBO_ITEMTYPE"};
	GetSkinRegistry( pData->m_ExportOption[iDumpMaxData::eOPTION_CHARACTERTYPE].m_SelectNum, regCombo[0], sizeof(int) );
	GetSkinRegistry( pData->m_ExportOption[iDumpMaxData::eOPTION_CHARACTERCLASS].m_SelectNum, regCombo[1], sizeof(int) );
	GetSkinRegistry( pData->m_ExportOption[iDumpMaxData::eOPTION_NPC].m_SelectNum, regCombo[2], sizeof(int) );
	GetSkinRegistry( pData->m_ExportOption[iDumpMaxData::eOPTION_ITEM].m_SelectNum, regCombo[3], sizeof(int) );
}